﻿using System.Windows;
using Gao.Poker.App.Print;
using Gao.Poker.App.ViewModel;
using Gao.Poker.Domain;
using Gao.Poker.Services;
using MessageBox = Xceed.Wpf.Toolkit.MessageBox;

namespace Gao.Poker.App.Members
{
    /// <summary>
    /// Interaction logic for RechargeWin.xaml
    /// </summary>
    public partial class RechargeWin : Window
    {
        public MemberViewModel ViewModel { get; set; }

        private Member _member;

        public Member Member
        {
            get { return _member; }
            set
            {
                _member = value;
                DataContext = _member;
            }
        }

        public RechargeWin()
        {
            InitializeComponent();
        }

        private void Confirm_Click(object sender, RoutedEventArgs e)
        {
            MemberService ms = MemberService.Instance();

            RechargeLog log = new RechargeLog();
            _member = ms.GetMember(_member.CardNo);

            log.MemberID = _member.ID;
            if (udRechargeMoney.Value != null)
            {
                _member.ConsumeMoney += udRechargeMoney.Value.Value;
                log.Money = udRechargeMoney.Value.Value;
                if (udPoints.Value != null)
                {
                    _member.Points += (udRechargeMoney.Value.Value + udPoints.Value.Value);
                    log.Points = (udRechargeMoney.Value.Value + udPoints.Value.Value);
                }
            }
          
            ms.Save(_member);
            RechargeLogService.Instance().Save(log);

            PrintHelper.Instance().MemberPrint(_member.Name, _member.CardNo, log.Points, _member.Points);
           
            ViewModel.OnPropertyChanged("Members");
            ViewModel.OnPropertyChanged("RechargeLogs");



            MessageBox.Show("充值成功！", "提示信息",MessageBoxButton.OK,MessageBoxImage.Information);
            Close();
        }
    }
}
